package com.thinkgem.jeesite.modules.tb_cost.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.thinkgem.jeesite.common.utils.ToolsUtil;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.web.ErrorCodeAndMsg;
import com.thinkgem.jeesite.modules.tb_cost.entity.TbCost;
import com.thinkgem.jeesite.modules.tb_cost.service.TbCostService;
/**
 * 运输中审核-费用APP接口
 * @author zhang
 *
 */
@Controller
@RequestMapping("app/tbCost/")
public class TbCostAppController extends BaseController{

	@Autowired
	private TbCostService tbCostService;
	
	@RequestMapping("save")
	@ResponseBody
	public Map<String,Object> save(
			HttpServletRequest request,
			@RequestParam("waybillId")String waybillId,
			@RequestParam("type")String type,//费用类型0配件费1维修费2过路费3协调费4住宿费5保养费6其他
			@RequestParam("money")String money,
			@RequestParam("dateTime")String dateTime,//时间
			@RequestParam("photoBig")String photoBig,// 照片
			@RequestParam("photoSmall")String photoSmall,// 照片
			@RequestParam("remarks")String remarks
			){
		int driverId = uid(request);
		if(driverId==-1)return returnError(ErrorCodeAndMsg.USER_NULL_CODE, ErrorCodeAndMsg.USER_NULL_CODE_MSG);
		try{
			
			TbCost tbCost = new TbCost();
			tbCost.setWaybillId(waybillId);
			tbCost.setDriverId(driverId);
			tbCost.setMoney(Double.parseDouble(money));
			tbCost.setType(type);
			tbCost.setState("0");
			tbCost.setDateTime(ToolsUtil.strToDate(dateTime, "yyyy-MM-dd"));
			tbCost.setRemarks(remarks);
			/*if(!"2".equals(type)&&!"3".equals(type)&&!"4".equals(type)){
				tbCost.setParst(parst);
			}*/
			tbCostService.save(tbCost);
		}catch(Exception e){
			return returnError(">>>运输中审核-费用添加异常", e);
		}
		return returnSuccess();
	}
	
	
}
